package pl.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import pl.model.dao.BookDao;
import pl.model.domain.Book;

@Controller
public class BookDetailsController  {

	protected final Log log = LogFactory.getLog(getClass());
	protected BookDao bookDao;
	protected Integer bookId;
        
	@RequestMapping("/bookDetails.htm")
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		bookId = Integer.parseInt(request.getParameter("bookId"));
		Book book = bookDao.findWithAuthor(bookId);
		
		return new ModelAndView("bookDetails", "book", book);
	}
	public void setBookDao(BookDao bookDao) {
		this.bookDao = bookDao;
	}

}
